package com.mtsmda.designPattern.singleton;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class SingletonSerializedTest {
	
	public static void main(String[] args) {
		SerializedSingleton serializedSingleton = null;
		SerializedSingleton serializedSingleton2 = null;
		try {
			serializedSingleton = SerializedSingleton.getInstance();
			ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("filename.ser")));
			objectOutputStream.writeObject(serializedSingleton);
			objectOutputStream.close();
			
			ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(new File("filename.ser")));
			serializedSingleton2 = (SerializedSingleton)objectInputStream.readObject();
			objectInputStream.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		System.out.println(serializedSingleton.hashCode());
		System.out.println(serializedSingleton2.hashCode());
	}
	
}